﻿using System;
using System.Web;

namespace VioletDevelopmentLaboratory.Net.Web.Component
{
	public class BoardParameters
	{
		private BoardParameters() { }

		public static BoardPart Part
		{
			get
			{
				try
				{
					return (BoardPart)Enum.Parse(typeof(BoardPart), HttpContext.Current.Request.QueryString["part"]);
				}
				catch
				{
					return BoardPart.List;
				}
			}
		}

		public static String ComponentID { get { return HttpContext.Current.Request.QueryString["cid"]; } }

		public static String CategoryID { get { return HttpContext.Current.Request.QueryString["cate"]; } }

		public static String FileID { get { return HttpContext.Current.Request.QueryString["fid"]; } }

		public static String ThreadID { get { return HttpContext.Current.Request.QueryString["tid"]; } }

		public static Int32 PageIndex
		{
			get
			{
				Int32 pageIndex = 0;

				Int32.TryParse(HttpContext.Current.Request.QueryString["pindex"], out pageIndex);

				return pageIndex;
			}
		}

		public static String SearchText
		{
			get
			{
				String searchText = HttpContext.Current.Request.QueryString["search"];

				if (!String.IsNullOrEmpty(searchText))
					return searchText.Replace('%', '％');

				return "";
			}
		}

		public static Int32 LastScrollX
		{
			get
			{
				Int32 x = 0;

				Int32.TryParse(HttpContext.Current.Request.Form["VWebCurrentScrollX"], out x);

				return x;
			}
		}

		public static Int32 LastScrollY
		{
			get
			{
				Int32 y = 0;

				Int32.TryParse(HttpContext.Current.Request.Form["VWebCurrentScrollY"], out y);

				return y;
			}
		}
	}
}
